#!/usr/bin/env bash

#get this script real directory
SOURCE="$0"
while [ -h "$SOURCE"  ]; do # resolve $SOURCE until the file is no longer a symlink
    this_script_dir="$( cd -P "$( dirname "$SOURCE"  )" && pwd  )"
    SOURCE="$(readlink "$SOURCE")"
    # if $SOURCE was a relative symlink, 
    #we need to resolve it relative to the path 
    #where the symlink file was located
    [[ $SOURCE != /*  ]] && SOURCE="$this_script_dir/$SOURCE"
done
this_script_dir="$( cd -P "$( dirname "$SOURCE"  )" && pwd  )"




log_level=${log_level:=info}

assist_dir=${assist_dir:=~/git/tool_sh/assist}
source $assist_dir/global.sh
################################################################################
#       
cur_dir=`pwd`

if [ `uname` == "Darwin" ] ; then
    ps aux | grep -v grep| grep auto_push_all.sh > /dev/null
    if [ $? -ne 0 ] ; then    #auto is not running
        nohup $this_script_dir/auto_push_all.sh > $log_file 2>&1 &
        vlogi "start auto_push_all.sh and output log into $log_file"
    else
        vlogi "auto_push_all.sh already running, it's log_file:$log_file"
    fi
elif [ `uname` == "Linux" ] ; then
    cd ~/git/cfg && ./git_daemon.sh &
    cd ~/git/hdocs/rest/build && ./rest

    if [ -d ~/git/ddns ] ; then
        nohup ~/git/ddns/shell/reset_domain_ip.sh &
    fi

    if [ -e ~/git/tool_sh/show.sh ] ; then
        nohup ~/git/tool_sh/show.sh --ip_upload --loop &
    fi

    #sudo nginx &
    vlogi "please start nginx by root or sudo."
    

#nohup /usr/lib/polkit-1/polkitd &

#sleep 2
#nohup dockerd &
fi

